<template>
  <el-row class="container">
    <el-col :span="24" class="header">
      <el-col
        :span="10"
        class="logo"
        :class="collapsed ? 'logo-collapse-width' : 'logo-width'"
      >{{ collapsed ? "" : sysName }}</el-col>
      <el-col :span="10">
        <div class="tools" @click.prevent="collapse">
          <i
            v-bind:class="{
              'el-icon-arrow-left': isLeft,
              'el-icon-arrow-right': isRight
            }"
          ></i>
        </div>
      </el-col>
      <el-col :span="4" class="userinfo">
        <el-dropdown trigger="hover">
          <span class="el-dropdown-link userinfo-inner">
            <strong>用户:</strong>
            {{ this.user.name }}
          </span>
          <el-dropdown-menu slot="dropdown">
            <!-- <el-dropdown-item>我的消息</el-dropdown-item> -->
            <el-dropdown-item @click.native="changePwdVisible = true">密码修改</el-dropdown-item>
            <el-dropdown-item divided @click.native="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-col>
    </el-col>
    <el-col :span="24" class="main">
      <aside :class="collapsed ? 'menu-collapsed' : 'menu-expanded'">
        <!--导航菜单-->
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          @open="handleopen"
          @close="handleclose"
          @select="handleselect"
          unique-opened
          router
          :collapse="collapsed"
        >
          <template v-for="(item, index) in $router.options.routes" v-if="!item.hidden">
            <template v-if="!item.children">
              <el-menu-item :index="item.path">
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span slot="title">{{ item.name }}</span>
                </template>
              </el-menu-item>
            </template>
            <template v-if="item.children">
              <el-submenu :index="index + ''" v-if="!item.leaf">
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span slot="title">
                    <!-- {{ collapsed ? "" : item.name }} -->
                    {{ item.name }}
                  </span>
                </template>
                <el-menu-item
                  v-for="child in item.children"
                  :index="child.path"
                  :key="child.path"
                  v-if="!child.hidden"
                >
                  <!-- {{ collapsed ? "" : child.name }} -->
                  {{ child.name }}
                </el-menu-item>
              </el-submenu>
              <el-menu-item
                v-if=" item.leaf && item.children.length > 0 "
                :index="item.children[0].path"
              >
                <i :class="item.iconCls"></i>
                {{ item.children[0].name }}
                <!-- {{ collapsed ? "" : item.children[0].name }} -->
              </el-menu-item>
            </template>
          </template>
        </el-menu>
      </aside>

      <section class="content-container">
        <div class="grid-content bg-purple-light">
          <el-col :span="24" class="breadcrumb-container">
            <strong class="title">{{ $route.name }}</strong>
            <el-breadcrumb separator="/" class="breadcrumb-inner">
              <el-breadcrumb-item v-for="item in $route.matched" :key="item.path">{{ item.name }}</el-breadcrumb-item>
            </el-breadcrumb>
          </el-col>
          <el-col :span="24" class="content-wrapper">
            <transition name="fade" mode="out-in">
              <router-view></router-view>
            </transition>
          </el-col>
        </div>
      </section>
    </el-col>
    <el-dialog
      title="密码修改"
      :visible.sync="changePwdVisible"
      :close-on-click-modal="false"
      width="40%"
    >
      <el-form ref="changePwdForm" label-width="80px">
        <el-form-item label="原密码">
          <el-input v-model="oldPwd" type="password"></el-input>
        </el-form-item>
        <el-form-item label="新密码">
          <el-input v-model="newPwd" type="password"></el-input>
        </el-form-item>
        <el-form-item label="确认密码">
          <el-input v-model="confirmPwd" type="password"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="changePwdVisible = false">取消</el-button>
        <el-button type="primary" @click.native="pwdSubmit" :loading="pwdoading">提交</el-button>
      </div>
    </el-dialog>
  </el-row>
</template>
<script>
import { password_update } from "../api/user";

// import { searchLeaveMan } from "../api/berth";
// import { sort } from "semver";
export default {
  data() {
    return {
      sysName: "宿舍管理系统",
      collapsed: false,
      changePwdVisible: false,
      oldPwd: null,
      newPwd: null,
      confirmPwd: null,
      pwdoading: false,
      isLeft: true,
      isRight: false,
      user: {
        name: null,
        power: null,
      },
    };
  },
  methods: {
    onSubmit() {
      console.log("submit!");
      if (condition) {
      }
    },
    handleopen() {
      //console.log('handleopen');
      var a = [
        { No: 1, name: "zxy" },
        { No: 1, name: "zxy" },
      ];
      // int a ;
    },
    handleclose() {
      //console.log('handleclose');
    },
    handleselect: function (a, b) {},
    //退出登录
    logout: function () {
      var _this = this;
      this.$confirm("确认退出吗?", "提示", {
        //type: 'warning'
      })
        .then(() => {
          sessionStorage.removeItem("user");
          _this.$router.push("/login");
        })
        .catch(() => {});
    },
    //折叠导航栏
    collapse: function () {
      this.collapsed = !this.collapsed;
      this.isLeft = !this.isLeft;
      this.isRight = !this.isRight;
    },
    showMenu(i, status) {
      this.$refs.menuCollapsed.getElementsByClassName(
        "submenu-hook-" + i
      )[0].style.display = status ? "block" : "none";
    },
    // 修改
    pwdSubmit() {
      // 验证前后密码是否一致
      let _this = this;
      if (_this.newPwd !== _this.confirmPwd) {
        _this.$alert("前后密码不一致,请重新输入", "错误提示", {
          confirmButtonText: "确定",
          callback: function () {
            _this.newPwd = null;
            _this.confirmPwd = null;
          },
        });
      } else {
        console.log(_this.user);
        password_update(_this.user.name, _this.newPwd).then((res) => {
          if (res) {
            this.changePwdVisible = false;
            this.$alert(res.msg, "操作", {
              confirmButtonTextL: "确定",
              // callback: action => {
              //   this.$message({
              //     type: "info",
              //     message: res.ret
              //   });
              // }
            });
          } else {
          }
        });
      }
    },
    // 增加离职人员系统功能
    leaveWarn() {
      // 获取离职未退宿人员名单
      this.$notify({
        title: "提示",
        message: "此处提示已离职但未退宿人员",
        duration: 0,
        type: "warning",
        position: "bottom-right",
        offset: 100,
      });
      // searchLeaveMan().then(res => {
      //   if (res) {
      //     console.log(res.msg);
      //   }
      // });
    },
  },
  mounted() {
    var user = sessionStorage.getItem("user");
    if (user) {
      this.user.name = user || "无此用户";
    } else {
      this.$router.push({ path: "/login" });
    }
    // this.leaveWarn();
  },
};
</script>
<style scoped lang="scss">
@import "../assets/style/vars.scss";

.container {
  position: absolute;
  margin: 0 0;
  top: 0px;
  bottom: 0px;
  width: 100%;
  .header {
    height: 60px;
    line-height: 60px;
    background: $color-primary;
    color: #fff;
    .userinfo {
      text-align: right;
      padding-right: 35px;
      float: right;
      .userinfo-inner {
        cursor: pointer;
        color: #fff;
        img {
          width: 40px;
          height: 40px;
          border-radius: 20px;
          margin: 10px 0px 10px 10px;
          float: right;
        }
      }
    } //

    .logo {
      //width:230px;
      height: 60px;
      font-size: 22px;
      padding-left: 20px;
      padding-right: 20px;
      border-color: rgba(238, 241, 146, 0.3);
      border-right-width: 1px;
      border-right-style: solid;
      img {
        width: 40px;
        float: left;
        margin: 10px 10px 10px 18px;
      }
      .txt {
        color: #fff;
      }
    }
    .logo-width {
      width: 230px;
    }
    .logo-collapse-width {
      width: 65px;
    }
    .tools {
      padding: 0px 23px;
      width: 14px;
      height: 60px;
      line-height: 60px;
      cursor: pointer;
    }
  }
  .main {
    display: flex;
    // background: #324057;
    position: absolute;
    top: 60px;
    bottom: 0px;
    overflow: hidden;
    aside {
      flex: 0 0 230px;
      width: 230px;
      // position: absolute;
      // top: 0px;
      // bottom: 0px;
      .el-menu {
        height: 100%;
      }
      // .collapsed {
      //   // width: 60px;
      //   // .item {
      //   //   position: relative;
      //   // }
      //   // .submenu {
      //   //   position: absolute;
      //   //   top: 0px;
      //   //   left: 60px;
      //   //   z-index: 99999;
      //   //   height: auto;
      //   //   display: none;
      //   // }
      // }
    }
    .menu-collapsed {
      flex: 0 0 60px;
      width: 60px;
    }
    .menu-expanded {
      flex: 0 0 230px;
      width: 230px;
    }
    .content-container {
      // background: #f1f2f7;
      flex: 1;
      text-align: left;
      // position: absolute;
      // right: 0px;
      // top: 0px;
      // bottom: 0px;
      // left: 230px;
      overflow-y: scroll;
      padding: 20px;
      .breadcrumb-container {
        //margin-bottom: 15px;
        .title {
          width: 200px;
          float: left;
          color: #475669;
        }
        .breadcrumb-inner {
          float: right;
        }
      }
      .content-wrapper {
        background-color: #fff;
        box-sizing: border-box;
      }
    }
  }
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 230px;
    min-height: 400px;
  }
  .magneticstick {
    position: relative;
    height: 10rem;
    width: 10rem;
    background-color: rgb(32, 160, 225);
    border-radius: 5rem;
    // text-align: center;
    // font-weight:bold;
    // font-size: 1rem;
    color: white;
    box-shadow: 0 0.1em 0.2em -0.05em rgba(0, 0, 0, 0.5);
  }
  .magneticstick:hover {
    // width: 11rem;
    // height: 11rem;
    // margin: -1px 0 0 -1px;
    transform: scale(1.1);
  }
}
</style>
